Skip to content

Convert Browser.workers to HandleAllocator. NFC#27127

Open
sbc100 wants to merge 1 commit into
emscripten-core:mainfrom
sbc100:workerHandles
Open

Convert Browser.workers to HandleAllocator. NFC#27127
sbc100 wants to merge 1 commit into
emscripten-core:mainfrom
sbc100:workerHandles

Conversation

@sbc100

@sbc100 sbc100 commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Using the common/shared HandleAllocator for all subsystems allows us to make improvements in the central location. For example, we can play around using externref_t instead of allocating integers on the JS side.

This also comes with codesize saving, at least for test_codesize_hello_dylink_all (I imagine because it already includes several HandleAllocator usages).

This also removes a field from the global Browser object.

@sbc100 sbc100 requested a review from kripken June 16, 2026 18:59
@sbc100 sbc100 changed the title Convert Browser.workers to HandleAllocator (using workerHandles global) Convert Browser.workers to HandleAllocator Jun 16, 2026
Comment thread src/build_as_worker.js
@kripken

kripken commented Jun 16, 2026

Copy link
Copy Markdown
Member

This avoids using a raw array and allows reusing IDs

How important are those goals? Workers are created quite rarely so I suspect that keeping this code minimal with a simple array is good enough. Did you see a problem somewhere?

@sbc100

sbc100 commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

This avoids using a raw array and allows reusing IDs

How important are those goals? Workers are created quite rarely so I suspect that keeping this code minimal with a simple array is good enough. Did you see a problem somewhere?

Yes, that isn't really the goal here. The goal is more about using the HandleAllocator consistently so if/when we improve it (or perhaps just delete in favor of managing externref_t) on the native side, we have single point of control where we all subsystems can benefit.

@sbc100

sbc100 commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

Updated the PR description.

This avoids using a raw array and allows reusing IDs.
Remove Browser.workers and use a new global helper workerHandles instead.
@sbc100 sbc100 changed the title Convert Browser.workers to HandleAllocator Convert Browser.workers to HandleAllocator. NFC Jun 17, 2026
@sbc100 sbc100 requested a review from kripken June 17, 2026 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants